import { createDiscreteApi } from "naive-ui";
import { defineNuxtPlugin } from "nuxt/app";
import { ref } from "vue";

export default defineNuxtPlugin((nuxtApp)=>{
  const bar=ref(null);
    nuxtApp.hook("app:mounted",(e)=>{
        if(!bar.value){
            const {loadingBar}=createDiscreteApi(["loadingBar"])
          bar.value=  loadingBar;
        }
        console.log("app:mounted")
    })
    nuxtApp.hook("app:start",(e)=>{
        bar.value?.start()
        console.log("app:start")
    })
    nuxtApp.hook("app:finish",(e)=>{
        bar.value?.finish()
        console.log("app:finish")
    })
    nuxtApp.hook("app:error",(e)=>{
        console.log(e,"eroor")
        if(process.client){
            setTimeout(()=>{
                bar.value?.finish()

            },150)
        }
        console.log("app:error")
    })

})